<?php
// 单例模式的实现

class SingleTon
{
  private static $instance = null;

  private function __construct() { /* 初始化代码 */ }
  private function __clone() { /* 禁止复制 */ }
  private function __wakeup() { 
    /* 禁止反序列化 */ 
    throw new \Exception('禁止反序列化');
  }

  public static function getInstance()
  {
    if (self::$instance == null) {
        self::$instance = new self();
    }
    return self::$instance;
  }
}

$a = SingleTon::getInstance();

$b = SingleTon::getInstance();

var_dump($a === $b);

var_dump($a);
var_dump($b);

